home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / fontutil.6 / fontutil / fontutils-0.6 / lib / xmessage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-13  |  3.0 KB  |  98 lines

  1. /* message.c: pop up a message for five seconds and then go away.
  2.  
  3. Copyright (C) 1992 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "config.h"
  20.  
  21. #include "xt-common.h"
  22. #include <X11/Shell.h>
  23. #include <X11/Xaw/Label.h>
  24.  
  25. #include "xmessage.h"
  26.  
  27. static void message_over (XtPointer, XtIntervalId *);
  28.  
  29.  
  30.  
  31. /* Make a popup child of the widget PARENT displaying the string S.  We
  32.    pass the ARGS and N_ARGS parameters to the creation routine.  */
  33.    
  34. void
  35. x_message (Widget parent, string s, ArgList args, Cardinal n_args)
  36. {
  37.   Dimension parent_height;
  38.   Position popup_x, popup_y;
  39.   Widget popup;
  40.   
  41.   XtAppContext app_con = XtWidgetToApplicationContext (parent);
  42.   Arg parent_args[]
  43.     = { { XtNheight,    (XtArgVal) &parent_height },
  44.       };
  45.   Arg popup_args[]
  46.     = { { XtNx,        0 }, /* We assign to the position below.  */
  47.         { XtNy,        0 },
  48.         { XtNgeometry,    (XtArgVal) NULL }, /* Don't use parent's geometry.  */
  49.       };
  50.  
  51.   Arg default_args[] = { { XtNlabel, (XtArgVal) s } };
  52.   ArgList all_args
  53.     = XtMergeArgLists (args, n_args, default_args, XtNumber (default_args));
  54.  
  55.   /* Put the message at the left edge of and about halfway down PARENT's
  56.      window.  We pass the address of true Position variables rather
  57.      than the address of the Arg values; in the latter case, the
  58.      endianness of the computer determines which half of the word the
  59.      answers get stored in, which is clearly bad.  */
  60.   XtGetValues (parent, parent_args, XtNumber (parent_args));
  61.   XtTranslateCoords (parent, 0, parent_height / 2, &popup_x, &popup_y);
  62.   popup_args[0].value = popup_x;
  63.   popup_args[1].value = popup_y;
  64.   
  65.   popup = XtCreatePopupShell ("message shell", transientShellWidgetClass,
  66.                               parent, popup_args, XtNumber (popup_args));
  67.  
  68.   /* We can't use XtNumber on `all_args', since it's a pointer.  */
  69.   (void)
  70.     XtCreateManagedWidget ("message", labelWidgetClass, popup, all_args,
  71.                            n_args + XtNumber (default_args)); 
  72.   
  73.   /* XtPopup realizes the window, etc.  */
  74.   XtPopup (popup, XtGrabNone);
  75.   
  76.   /* Leave the message there for five seconds.  */
  77.   (void) XtAppAddTimeOut (app_con, 5000, message_over, popup); 
  78. }
  79.  
  80.  
  81. /* Just a convenient interface to the above.  */
  82.  
  83. void
  84. x_warning (Widget parent, string s)
  85. {
  86.   x_message (parent, concat (s, "."), NULL, 0);
  87. }
  88.  
  89.  
  90.  
  91. static void
  92. message_over (XtPointer client_data, XtIntervalId *interval_id)
  93. {
  94.   Widget popup = (Widget) client_data;
  95.   
  96.   XtPopdown (popup);
  97. }
  98.